import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
import VueLazyload from 'vue-lazyload'
import infiniteScroll from 'vue-infinite-scroll'
import VueCookie from 'vue-cookie'
import { userInfo } from './api'
import { Pagination, Message, MessageBox, Loading, Steps, Step, Button, Dialog, Select, Option, Rate, Tabs, TabPane, } from 'element-ui'
import { Carousel, CarouselItem } from 'element-ui'
import VueQuillEditor from 'vue-quill-editor'
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Rate)
Vue.use(Select)
Vue.use(Option)
Vue.use(Dialog)
Vue.use(Button)
Vue.use(Pagination)
Vue.use(Loading.directive)
Vue.prototype.$loading = Loading.service
Vue.use(Steps)
Vue.use(Step)
Vue.use(VueQuillEditor, /* { default global options } */ )
Vue.use(Carousel)
Vue.use(CarouselItem)
Vue.use(infiniteScroll)
Vue.use(VueCookie)
Vue.use(VueLazyload, {
	// preLoad: 1.3,
	// error: 'dist/error.png',
	loading: '/static/images/load.gif'
	// attempt: 1
})
Vue.config.productionTip = false
Vue.prototype.$message = Message
Vue.prototype.$MessageBox = MessageBox
//Vue.prototype.root = 'http://pstsc.pstech360.com/'
Vue.prototype.root = 'http://115.28.237.109/'
// 不需要登陆的页面 => 白名单
const whiteList = ['/home', '/goods', '/login', '/test']
router.beforeEach(function(to, from, next) {
	//模板参数
	window.localStorage.muban = 2;
	userInfo().then(res => {
		// 没登录
		if(res.code===101||res.code===403) {
			// 白名单
			if(whiteList.indexOf(to.path) !== -1) {
				next()
			} else {
				next('/login')
			}
		} else {
			store.commit('RECORD_USERINFO', {
				info: res.data.list[0],
			})
			//跳转到
			if(to.path === '/login') {
				next({
					path: '/'
				})
			}
			next()
		}
	})
})

/* eslint-disable no-new */
new Vue({
	el: '#app',
	store,
	router,
	render: h => h(App)
})